package org.scboy.rbac.controller;

import org.scboy.common.annotation.Menu;
import org.scboy.common.annotation.Permission;
import org.scboy.common.request.Result;
import org.scboy.rbac.service.UserRoleService;
import org.scboy.utils.entitys.coobi.Model;
import org.scboy.utils.entitys.coobi.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/rbac/userrole/")
@Menu("权限管理系统.用户角色管理")
public class UserRoleController {
	
	@Autowired
	UserRoleService service;
	

	@PostMapping("page")
	@Permission("分页查询用户角色")
	public Result page(@RequestBody Model params) {
		Page page=service.page(params);
		return Result.Success(page);
	}
	
	@PostMapping("add")
	@Permission("新增用户角色")
	public Result add(String ojId,String userId){
		boolean check=service.add(ojId,userId);
		if(check) {
			return Result.Success("RBAC_USER_ROLE_ADD_SUCCESS");
		}else {
			return Result.Error("RBAC_USER_ROLE_ADD_ERROR");
		}
	}
	
	@PostMapping("adds")
	@Permission("新增多个用户角色")
	public Result adds(String ojId,String [] userId){
		boolean check=service.add(ojId,userId);
		if(check) {
			return Result.Success("RBAC_USER_ROLE_ADD_SUCCESS");
		}else {
			return Result.Error("RBAC_USER_ROLE_ADD_ERROR");
		}
	}
	
	@DeleteMapping("delete")
	@Permission("删除用户角色")
	public Result delete(String id){
		boolean check=service.delete(id);
		if(check) {
			return Result.Success("RBAC_USER_ROLE_DELETE_SUCCESS");
		}else {
			return Result.Error("RBAC_USER_ROLE_DELETE_ERROR");
		}
	}
}
